﻿using BLL;
using BLL.BarCode;
using Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebProject.Controllers.Base;

namespace WebProject.Controllers
{
    public class BarController : BaseController
    {
        BarBLL barBLL;
      SysFrameWork.SystemBLL sysBLL;
        public BarController()
        {
            barBLL = new BarBLL();
            sysBLL = new SysFrameWork.SystemBLL();
        }
        //
        // GET: /Bar/
        public ActionResult BarCodeInfo()
        {
            return View();
        }

        public ActionResult BoxCodeInfo()
        {
            return View();
        }

        public ActionResult BarZhanYong()
        {
            return View();
        }
        public ActionResult AddBarCode()
        {
            return View();
        }
        public ActionResult BarRecords()
        {
            return View();
        }
        public ActionResult TempBars()
        {
            return View();
        }
        public ActionResult RecordsList()
        {
            return View();
        }
        public ActionResult BarOutHouse()
        {
            return View();
        }
        public ActionResult OutOrder()
        {
            return View();
        }
        public ActionResult PrintBar()
        {
            // ViewData["operate"] = sysBLL.getUserPower("", "printBar").Data.ToString();
            return View();
        }
        public ActionResult ReSetBar()
        {
            return View();
        }
        public ActionResult BarInHouse()
        {
            return View();
        }
        public ActionResult PlanPrintBar()
        {
            return View();
        }

        public ActionResult SBBarCodeInfo()
        {
            return View();
        }

        /// <summary>
        /// 销售入库单
        /// </summary>
        /// <returns></returns>
        public ActionResult Warehousing()
        {
            return View();
        }
        public ActionResult WaterWashCodeList()
        {
            return View();
        }

        [HttpGet]
        public JsonResult GetDataList(string page, string limit, string condition, string dataType)
        {
            string pageCount = "1";
            string msg = "";
            var datas = new object();
            var rsl = new ReturnResult();
            if (dataType == "bar")
            {
                rsl = barBLL.getBarCodeList(page, limit, ref pageCount, condition, "");//条码档案
            }
            else if (dataType == "barIn")
            {
                rsl = barBLL.getBarCodeInList(page, limit, ref pageCount, condition, "proCode,spec,barCode desc");
            }
            else if (dataType == "records")
            {
                rsl = barBLL.getBarEntryRecords(page, limit, ref pageCount, condition);
            }
            else if (dataType == "reList")
            {
                rsl = barBLL.getRecordsListByCode(condition);
            }
            else if (dataType == "sw")
            {
                rsl = barBLL.saleWareHousing(condition);
            }
            else if (dataType == "tsb")
            {
                rsl = barBLL.loadTempScanTotal(condition);
            }
            else if (dataType == "tbsd")
            {
                rsl = barBLL.loadTempData(condition);
            }
            else if (dataType == "bzy")
            {
                rsl = barBLL.GetBarZhanYongInfo(condition);
            }
            else if (dataType == "outOrder")
            {
                BLL.BarCode.ServiceBLL serBLL = new BLL.BarCode.ServiceBLL();
                rsl = serBLL.SendOrderInfo(condition);
            }
            else if (dataType == "olt")
            {
                BLL.BarCode.ServiceBLL serBLL = new BLL.BarCode.ServiceBLL();
                rsl = serBLL.OrderList(condition);
            }
            else if (dataType == "barS")
            {
                BLL.BarCode.ServiceBLL serBLL = new BLL.BarCode.ServiceBLL();
                rsl = barBLL.BarInWareHouse(condition);
            }
            if (rsl.Result)
            {
                datas = rsl.Data;
            }
            else
            {
                msg = rsl.Message;
            }
            JsonResult js = new JsonResult();
            return new JsonResult()
            {
                Data = new
                {
                    count = pageCount,
                    msg = msg,
                    code = "0",
                    data = datas
                },
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };
        }
        public JsonResult getProductInfoByBarCode(string barCode)
        {
            var bar_BLL = new BarBLL();
            return Json(bar_BLL.getProductInfoByBarCode(barCode));
        }
       

        [HttpPost]
        public JsonResult DropBarCode(string barCode)
        {
            var bar_BLL = new BarBLL();
            return Json(bar_BLL.DropBarCode(barCode));
        }
     
        [HttpPost]
        public JsonResult DropZhanYong(string barCodes)
        {
            var bar_BLL = new BarBLL();
            return Json(bar_BLL.DropZhanYong(barCodes));
        }

        [HttpPost]
        public JsonResult DelTempScan(string dataId)
        {
            var bar_BLL = new BarBLL();
            return Json(bar_BLL.DelTempScan(dataId));
        }
        [HttpPost]
        public JsonResult SubmitInHouse(string tempCode)
        {
            var bar_BLL = new BarBLL();
            return Json(bar_BLL.SubmitInHouse(tempCode));
        }
    
        [HttpPost]
        public JsonResult BackInWareHouse(string mCode)
        {
            BLL.BarCode.ServiceBLL serBLL = new BLL.BarCode.ServiceBLL();
            return Json(barBLL.BackInWareHouse(mCode));
        }
        [HttpPost]
        public JsonResult ReSetBar(string datas)
        {
            return Json(barBLL.ResetBarInfo(datas));
        }

        //修改在库条码所在位置（仓库 货位）
        [HttpPost]
        public JsonResult updateWarePosition()
        {
            return Json(barBLL.updateWarePosition());
        }

    }
}